%% objpats.hrl
%%   Definitions for objpats.erl and modules using it.
%%
%% Copyright (C) 2008, 2009 Gábor Fehér
%%
%% This file is part of ECT.
%% 
%% ECT is free software: you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation, either version 3 of the License, or
%% (at your option) any later version.
%% 
%% ECT is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.
%% 
%% You should have received a copy of the GNU General Public License
%% along with ECT.  If not, see <http://www.gnu.org/licenses/>.
%%
%%

-record(flatitem,
    {type::eq|guard,      %% eq - equality, guard
     arg,                 %% the variable or constant on the left of this item
     expr                 %% the path of this flatitem
    }).
%% example
%% a pattern match: X = {A, {C, xyz}} is translated by objpats.erl to 
%%      the following simple items:
%%           A = element(1, X)
%%           C = element(1, element(2, X))
%%           xyz = element(2, element(2, X))
%%       which is represented by the following list of flatitems:
%%         [
%%          #flatitem{arg = A, type = eq, expr = //element(1, X)//},  
%%          #flatitem{arg = C, type = eq, expr = //element(1, element(2, X))//},
%%          #flatitem{arg = xyz, type = guard, path = //element(2, element(2, X))//},
%%         ]
%%       where //xxx// represents the abstract syntax tree representation of source code xxx
%% The basic idea is that the variables and constants in the pattern can be expressed from X, the left hand variable.
%% The this expression is in #flatitem.expr, and the the variable/constant itself is in #flatitem.arg.
%% The type determines that the flatitem can be used in a guard, like:
%%    xyz =:= element(2, element(2, X))
%% or not because e.g. A is unbound:
%%    A = element(1, X)
%% 
%% The pattern match only contained tuple-patterns in this example, but
%% list-patterns, record-patterns, class-patterns, erc. are also supported.


%%---------------------------------------------------------------------
%% Data Type: #relaxstate{}
%% Purpose: the status of processing a pattern
%%----------------------------------------------------------------------
-record(relaxstate,
    {expr_path,  % ::an AST expression   %% the current path in the pattern while parsing, this is copied to flatitems
     list::[#flatitem{}],                %% the list of created #flatitems{}
     mode::normal|shallow,               %% normal/shallow
     records::[{record, _, _}],          %% list of record definitions see module recrods
     classes, %::[#class{}],             %% information about visible classes in the source code
     cx_class::atom()                    %% the class in which the current pattern is implemented, it is set to [] if the pattern is in a module (needed for field visibility checking)
	}).

